<template>
	<view class="uni_box home">
		<navbar title='联系我们'>
		</navbar>
		<view class="content">
			<view class="lone">
				<view class="shu"></view>
				<view class="lbiao">
					客服微信二维码
				</view>
			</view>
			<view class="maview">
				<view class="ma">
					<image class="maimg" :src="info.setting.customer_code"></image>
					<!-- <uv-qrcode ref="qrcode" size="150px" v-if="address" :value="address"></uv-qrcode> -->
				</view>
				<view class="xunview" @click="baocun">
					<image class="icon_ewm" src="/static/img/icon_ewm.png"></image>
					<text>保存二维码至相册</text>
				</view>
			</view>
			<view class="lone">
				<view class="shu"></view>
				<view class="lbiao">
					客服微信号
				</view>
			</view>
			<view class="wview">
				<text class="weiname">{{info.setting.customer_wechat}}</text>
				<view class="fuzhi" @click="copy(info.setting.customer_wechat)">复制</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				address:'http://www.baidu.com',
				share_url:'',
				info:{
					setting:{
						customer_code:'',
						customer_wechat:''
					}
				}
			}
		},
		onLoad() {
			this.getuserinfo();
		},
		onShow() {
		},
		methods: {
			async getuserinfo(){
				let res = await this.$u.api.userinfo({
				});
				this.info = res
				this.share_url = res.share_url
			},
			baocun() {
				//保存相册
				// #ifdef APP-PLUS
				this.loadBase64Url()
				// #endif
				// #ifdef H5
				// uni.showToast({
				// 	title: '请截图保存相册',
				// 	icon: 'none',
				// 	duration: 1000
				// });
				let shuzu = []
				shuzu.push(this.info.setting.customer_code)
				uni.previewImage({
					current: this.info.setting.customer_code, // 当前显示图片的 http 链接
					urls: shuzu // 需要预览的图片 http 链接列表
				});
				// #endif
				},
				loadBase64Url() {
				this.saveImage(this.info.setting.customer_code)
				},
				// 保存图片到手机相册
				saveImage(filePath) {
				let that = this
				uni.saveImageToPhotosAlbum({
					filePath, // 需要临时文件路径，base64无法保存
					success: () => {
					uni.showToast({
						title: '保存图片成功',
						icon: 'none',
						duration: 1000
					});
					},
					fail: () => {
					uni.showToast({
						title: '保存失败，请重试',
						icon: 'none',
						duration: 1000
					});
					}
				});
				},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		background-color: #fff;
		padding: 30rpx;
		min-height: 100vh;
		.lone{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 44rpx;
			.shu{
				width: 6rpx;
				height: 26rpx;
				background: #3E65E5;
				display: inline-block;
				margin-right: 13rpx;
			}
			.lbiao{
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #333333;
			}
		}
		.maview{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin-bottom:70rpx;
			.ma{
				margin-top: 40rpx;
			}
			.maimg{
				width: 300rpx;
				height: 300rpx;
				border-radius: 10rpx;
			}
			.xunview{
				width: 400rpx;
				height: 100rpx;
				background: #3E65E5;
				border-radius: 10rpx;
				margin-top: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				.icon_ewm{
					width: 32rpx;
					height: 32rpx;
					margin-right: 20rpx;
				}
				text{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
				}
			}
		}
		.wview{
			height: 88rpx;
			background: #F5F5F5;
			border-radius: 10rpx;
			padding: 0 20rpx 0 30rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			.weiname{
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #666666;
			}
			.fuzhi{
				margin-left: auto;
				width: 160rpx;
				height: 60rpx;
				background: #496EE7;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #F5F5F5;
			}
		}
	}
</style>
